package de.tabuma.ssoweb.controller;

import de.tabuma.lib.tabumacontroller;
import java.io.*;
import java.text.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import de.tabuma.ssoweb.view.*;
import java.util.Hashtable;

/**
 * This is the maincontroller class that is called from login.
 * It forwards to the controller depending on the main navigation
 * @see de.tabuma.wsdl2xform.login
 * @author $Author: alefen $
 * @version $Revision: 1.1.4.1 $
 * @since $Date: 2010/01/13 10:23:45 $
 */
public class controller extends tabumacontroller {

    private static Logger log =  Logger.getLogger(controller.class.getName());

    private de.tabuma.ssoweb.start.controller.controller startcontroller;
    private de.tabuma.sso.project.ProjectController projectcontroller;
    private de.tabuma.customer.controller.controller customercontroller;
    private de.tabuma.sso.group.GroupController groupcontroller;
    private de.tabuma.sso.user.UserController usercontroller;
    private de.tabuma.sso.shopping.ShoppingController shoppingcontroller;

    public controller(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }
    
    public void navigate(ServletContext context, HttpServletRequest request,HttpServletResponse response,PrintWriter out) {
        String mainnav = request.getParameter(constants.MAINNAV);
        if(mainnav==null) {
            mainnav = "" + constants.NAVID_START;
        }
        int mainnavInt = Integer.valueOf(mainnav);
        head head = new head(this.getServlet(), this.getParameter());
        head.processRequest(context, request, response,out);
        switch(mainnavInt) {
            case constants.NAVID_START:
                this.startcontroller = new de.tabuma.ssoweb.start.controller.controller(this.getServlet(), this.getParameter());
                log.fine("Giving the focus to the startcontroller.");
                this.startcontroller.navigate(context, request, response,out);
                break;
                
            case constants.NAVID_CUSTOMER:
                Hashtable hash = this.getParameter();
                hash.put(constants.MAINNAV, ""+constants.NAVID_CUSTOMER);
                this.customercontroller = new de.tabuma.customer.controller.controller(this.getServlet(), hash);
                log.fine("Giving the focus to the customer controller.");
                this.customercontroller.navigate(context, request, response,out);
                break;

            case constants.NAVID_PROJECTS:
                Hashtable hash1 = this.getParameter();
                hash1.put(constants.MAINNAV, ""+constants.NAVID_PROJECTS);
                this.projectcontroller = new de.tabuma.sso.project.ProjectController(this.getServlet(), hash1);
                log.fine("Giving the focus to the project controller.");
                this.projectcontroller.navigate(context, request, response,out);
                break;

            case constants.NAVID_GROUPS:
                Hashtable hash2 = this.getParameter();
                hash2.put(constants.MAINNAV, ""+constants.NAVID_GROUPS);
                this.groupcontroller = new de.tabuma.sso.group.GroupController(this.getServlet(), hash2);
                log.fine("Giving the focus to the group controller.");
                this.groupcontroller.navigate(context, request, response, out);
                break;

            case constants.NAVID_USER:
                Hashtable hash3 = this.getParameter();
                hash3.put(constants.MAINNAV, ""+constants.NAVID_USER);
                this.usercontroller = new de.tabuma.sso.user.UserController(this.getServlet(), hash3);
                log.fine("Giving the focus to the user controller.");
                this.usercontroller.navigate(context, request, response, out);
                break;

            case constants.NAVID_SHOPPING:
                Hashtable hash4 = this.getParameter();
                hash4.put(constants.MAINNAV, ""+constants.NAVID_SHOPPING);
                this.shoppingcontroller = new de.tabuma.sso.shopping.ShoppingController(this.getServlet(), hash4, de.tabuma.sso.constants.SHOPPING_PARAM);
                log.fine("Giving the focus to the shopping controller.");
                this.shoppingcontroller.navigate(context, request, response, out);
                break;

        }
        bottom bottom = new bottom(this.getServlet(), this.getParameter());
        bottom.processRequest(context, request, response,out);
    }
}